package com.makefriends.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.makefriends.R;
import com.makefriends.adapter.CommonPagerAdapter2;

import java.util.ArrayList;

/**
 * Created by sks on 2016/3/7.
 */
public class ThirdEmailFragment2 extends LazyFragment implements ViewPager.OnPageChangeListener {

    public static int CLASS_TYPE = 0;
    private View mView;

//    @Bind(R.id.email_viewpager)
    /**
     * 我的 ViewPager
     */
    private ViewPager mViewPager;

    /**
     * tab
     */
    private TextView mFirstLine;
    private TextView mSecondLine;
    private TextView mThirdLine;


    private Activity mContext;
    private CommonPagerAdapter2 mAdapter;

    protected int mCurrentTab = 0;
    protected int mLastTab = -1;

    private ArrayList<Fragment> pages= new ArrayList<>();

    @Override
    protected void lazyLoad() {

    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        mContext = activity;
    }

    @Override
    protected View doCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        mView = inflater.inflate(R.layout.fragment_email2,container,false);
//        ButterKnife.bind(mContext);
        mViewPager = (ViewPager) mView.findViewById(R.id.email_viewpager);
        mFirstLine = (TextView) mView.findViewById(R.id.first_line);
        mSecondLine = (TextView) mView.findViewById(R.id.second_dline);
        mThirdLine = (TextView) mView.findViewById(R.id.third_line);

        //添加页卡视图
        pages.add(new EmailNoticFragment());
        pages.add(new EmailChatFragment());
        pages.add(new EmailRecentContactFragment());

        mAdapter = new CommonPagerAdapter2(getChildFragmentManager(),pages);
        mViewPager.setAdapter(mAdapter);
        mViewPager.setCurrentItem(mCurrentTab);
        mLastTab = mCurrentTab;

        return mView;
    }


    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        mCurrentTab = position;
        CLASS_TYPE = position;
        if (position == 0){
            mFirstLine.setVisibility(View.VISIBLE);
            mSecondLine.setVisibility(View.GONE);
            mThirdLine.setVisibility(View.GONE);
        }else if (position == 1){
            mFirstLine.setVisibility(View.GONE);
            mSecondLine.setVisibility(View.VISIBLE);
            mThirdLine.setVisibility(View.GONE);
        }else {
            mFirstLine.setVisibility(View.GONE);
            mSecondLine.setVisibility(View.GONE);
            mThirdLine.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onPageScrollStateChanged(int state) {
        if (state == ViewPager.SCROLL_STATE_IDLE) {
            mLastTab = mCurrentTab;
        }
    }
}
